<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>

<script>
description("Test inputs to HKDF importKey()");

jsTestIsAsync = true;

var extractable = false;
rawBytes = new Uint8Array([1, 2]);

var p = Promise.resolve(null);
p.then(function() {
    debug("\nimportKey() with 'encrypt' usage...");
    return crypto.subtle.importKey("raw", rawBytes, "HKDF", extractable, ['encrypt']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with null key data...");
    return crypto.subtle.importKey("raw", null, "HKDF", extractable, ['deriveKey']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with jwk format...");
    return crypto.subtle.importKey("jwk", {kty: "HKDF"}, "HKDF", extractable, ['deriveKey']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with spki format...");
    return crypto.subtle.importKey("spki", rawBytes, "HKDF", extractable, ['deriveKey']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with empty usages...");
    return crypto.subtle.importKey("raw", rawBytes, "HKDF", extractable, []);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with extractable=true ...");
    return crypto.subtle.importKey("raw", rawBytes, "HKDF", true, ['deriveKey']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);
}).then(finishJSTest, failAndFinishJSTest);

</script>

</body>
</html>
